package com.windgo.service;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.windgo.bean.MarketAdminUpdateAdminVo;
import com.windgo.bean.*;
import com.windgo.bean.bo.PermissionsBO;
import com.windgo.bean.bo.RoleCreateBO;
import com.windgo.bean.common.BasePageInfo;
import com.windgo.bean.common.BasePageInfo1;
import com.windgo.bean.common.CommonData;
import com.windgo.bean.vo.*;
import com.windgo.mapper.MarketAdminMapper;
import com.windgo.mapper.MarketPermissionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.Array;
import java.util.*;

/**
 * @author stone
 * @date 2022/09/06 11:44
 */
@Service
public class AdminServiceImpl implements AdminService {

    @Autowired
    MarketAdminMapper adminMapper;

    @Autowired
    MarketPermissionMapper marketPermissionMapper;

    @Override
    public MarketAdmin queryById(Integer id) {
        MarketAdmin marketAdmin = adminMapper.selectByPrimaryKey(id);
        return marketAdmin;
    }

    @Override
    public void modify(MarketAdmin admin) {
        adminMapper.updateByPrimaryKeySelective(admin);
    }

    @Override
    public List<MarketAdmin> query(String username, String password, String[] avatars,
                                   Integer page, Integer limit) {
        // 执行查询之前 → 使用PageHelper开启分页就可以了
        PageHelper.startPage(page, limit);
        MarketAdminExample example = new MarketAdminExample();
        example.setDistinct(true);
        //example.setOrderByClause("username asc");
        // List<Criterion> 向这个列表里塞入数据
        // 条件查询

        MarketAdminExample.Criteria criteria = example.createCriteria();//这个实例里封装了Criterion的列表
        // 使用Example中的Criteria提供的方法，就可以构造Criterion实例，并且呢添加到list中
        /*criteria.andUsernameEqualTo(username)
                .andPasswordLike("%" + password + "%")
                .andAvatarIn(Arrays.asList(avatars));*/
        if (username != null && !"".equals(username)) {//StringUtils isEmpty
            criteria.andUsernameEqualTo(username);
        }
        if (password != null && !"".equals(password)) {

            criteria.andPasswordLike("%" + password + "%");
        }
        if (avatars != null && avatars.length > 0) {

            criteria.andAvatarIn(Arrays.asList(avatars));
        }
        List<MarketAdmin> marketAdmins = adminMapper.selectByExample(example);
        // page limit total
        // 把mybatis查询出来的原始结果放进去
        PageInfo pageInfo = new PageInfo(marketAdmins);
        long total = pageInfo.getTotal();
        return marketAdmins;
    }

    @Override
    public PageInfo<MarketStorage> listStorage(BasePageInfo basePageInfo, String key, String name) {
        //开启分页
        PageHelper.startPage(basePageInfo.getPage(), basePageInfo.getLimit());

        //执行查询过程中拼接分页信息
        //    List<MarketStorage> list = adminMapper.listStorage(basePageInfo.getSort(), basePageInfo.getOrder());

        MarketStorageExample marketStorageExample = new MarketStorageExample();
        //排序
        marketStorageExample.setOrderByClause(basePageInfo.getSort() + " " + basePageInfo.getOrder());
        MarketStorageExample.Criteria criteria = marketStorageExample.createCriteria();
        //key是精准查
        if (!StringUtil.isEmpty(key)) {
            criteria.andKeyEqualTo(key);
        }
        //name是模糊查询
        if (!StringUtil.isEmpty(name)) {
            criteria.andNameLike("%" + name + "%");
        }
        criteria.andDeletedEqualTo(false);
        //执行查询过程中拼接分页信息
        List<MarketStorage> list = adminMapper.selectByStorageExample(marketStorageExample);

        PageInfo<MarketStorage> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public int createStorage(MarketStorage marketStorage) {
        int number = adminMapper.insertMarketStorage(marketStorage);
        if (number == 1) {
            return 1;
        }
        return 0;
    }

    @Override
    public MarketStorage queryMarketStorage(Integer id) {
        MarketStorage marketStorage = adminMapper.queryMarketStorageById(id);
        return marketStorage;
    }

    @Override

    public CommonData<MarketAdmin> list(BasePageInfo info, String username) {
        PageHelper.startPage(info.getPage(), info.getLimit());
        MarketAdminExample example = new MarketAdminExample();
        MarketAdminExample.Criteria criteria = example.createCriteria();

        if (!StringUtil.isEmpty(username)) {
            criteria.andUsernameLike("%" + username + "%");
        }
        //typehandler在这里生效
        List<MarketAdmin> list = adminMapper.selectByExample(example);
        PageInfo<MarketAdmin> pageInfo = new PageInfo<>(list);
        return CommonData.data(pageInfo);
    }

    @Override
    public CommonData<MarketTopic> topicList(BasePageInfo info) {
        PageHelper.startPage(info.getPage(), info.getLimit());
        MarketTopicExample example = new MarketTopicExample();
        if (info.getOrder() != null && info.getSort() != null){
            example.setOrderByClause(info.getSort()+" "+info.getOrder());
        }
        List<MarketTopic> list = adminMapper.selectByExample1(example);
        PageInfo<MarketTopic> pageInfo = new PageInfo<>(list);
        return CommonData.data(pageInfo);
    }

    @Override
    public MarketTopicVo insertTopic(MarketTopic marketTopic) {

        int count = adminMapper.insertTopic(marketTopic);
        MarketTopicVo marketTopicVo = adminMapper.selectMarketTopicExampleById(marketTopic.getId());
        return marketTopicVo;
    }

    @Override
    public MarketGoodsDataEntity selectGoodsAndTopicById(Integer id) {
        MarketTopic marketTopic = adminMapper.selectMarketTopicById(id);
        List<MarketGoodsList> marketGoods = new ArrayList<>();
        Integer[] goods = marketTopic.getGoods();
        for (Integer good : goods) {
            MarketGoodsList list = adminMapper.selectMarketGoodsByGoodsId(good);
            marketGoods.add(list);
        }
        MarketGoodsDataEntity marketGoodsDataEntity = new MarketGoodsDataEntity();
        marketGoodsDataEntity.setGoodsList(marketGoods);
        marketGoodsDataEntity.setTopic(marketTopic);
        return marketGoodsDataEntity;
    }

    @Override
    public MarketTopic updateTopic(MarketTopic marketTopic) {

        adminMapper.updateMarketTopic(marketTopic);
        MarketTopic marketTopic1 = adminMapper.selectMarketTopicById(marketTopic.getId());
        return marketTopic1;
    }

    @Override
    public int deleteMarketTopicById(Integer id) {

        try {
            adminMapper.deleteMarketTopicById(id);
            return 200;
        } catch (Exception e) {
            return 404;
        }
    }

    @Override
    public CommonData<MarketAdminAdminListVo> selectAdminList(BasePageInfo info) {
        PageHelper.startPage(info.getPage(), info.getLimit());
        MarketAdminExample example = new MarketAdminExample();
        if (info.getSort() != null && info.getOrder() != null){
            example.setOrderByClause(info.getSort()+" "+info.getOrder());
        }

        List<MarketAdminAdminListVo> list = adminMapper.selectByAdminAdminList(example);
        PageInfo<MarketAdminAdminListVo> pageInfo = new PageInfo<>(list);

        return CommonData.data(pageInfo);
    }

    @Override
    public MarketAdminAdminCreateVo insertAdmin(MarketAdminAdminCreateVo adminListVo) {

        int count = adminMapper.insertAdmin(adminListVo);
        MarketAdminAdminCreateVo adminCreateVo = new MarketAdminAdminCreateVo();
        if (count == 1) {
            adminCreateVo = adminMapper.selectMarketAdmin(adminListVo.getUsername());
        }

        return adminCreateVo;
    }

    @Override
    public CommonData<MarketLog> selectLogList(BasePageInfo info) {
        PageHelper.startPage(info.getPage(), info.getLimit());
        MarketLogExample example = new MarketLogExample();
        example.setOrderByClause("add_time desc");//设置排序方式
        List<MarketLog> list = adminMapper.selectLogList(example);
        PageInfo<MarketLog> pageInfo = new PageInfo<>(list);
        return CommonData.data(pageInfo);
    }


    public int deleteStorage(MarketStorage marketStorage) {
        int affectedRows = adminMapper.deleteStorage(marketStorage);
        return affectedRows;
    }

    @Override
    public int updateStorage(MarketStorage marketStorage) {
        int affectedRows = adminMapper.updateStorage(marketStorage);
        return affectedRows;
    }


    @Override
    public MallInfoVO mallInfo() {
        MallInfoVO mallInfoVO = new MallInfoVO();
        List<MarketSystem> list = adminMapper.selectAllMallInfo();
        for (MarketSystem marketSystem : list) {
            if (marketSystem.getKeyName().equals("market_mall_longitude")) {
                mallInfoVO.setMarket_mall_longitude(marketSystem.getKeyValue());
            } else if (marketSystem.getKeyName().equals("market_mall_latitude")) {
                mallInfoVO.setMarket_mall_latitude(marketSystem.getKeyValue());
            } else if (marketSystem.getKeyName().equals("market_mall_address")) {
                mallInfoVO.setMarket_mall_address(marketSystem.getKeyValue());
            } else if (marketSystem.getKeyName().equals("market_mall_qq")) {
                mallInfoVO.setMarket_mall_qq(marketSystem.getKeyValue());
            } else if (marketSystem.getKeyName().equals("market_mall_phone")) {
                mallInfoVO.setMarket_mall_phone(marketSystem.getKeyValue());
            } else if (marketSystem.getKeyName().equals("market_mall_name")) {
                mallInfoVO.setMarket_mall_name(marketSystem.getKeyValue());
            }
        }
        return mallInfoVO;
    }

    @Override
    public int updateMallConfig(MallInfoVO mallInfoVO) {
        List<MarketSystem> list = adminMapper.selectAllMallInfo();
        for (MarketSystem marketSystem : list) {
            String keyName = marketSystem.getKeyName();
            if (keyName.equals("market_mall_longitude")) {
                String longitude = mallInfoVO.getMarket_mall_longitude();
                adminMapper.updateConfigInfo(longitude, keyName);
            } else if (keyName.equals("market_mall_latitude")) {
                String latitude = mallInfoVO.getMarket_mall_latitude();
                adminMapper.updateConfigInfo(latitude, keyName);
            } else if (keyName.equals("market_mall_address")) {
                String address = mallInfoVO.getMarket_mall_address();
                adminMapper.updateConfigInfo(address, keyName);
            } else if (keyName.equals("market_mall_qq")) {
                String qq = mallInfoVO.getMarket_mall_qq();
                adminMapper.updateConfigInfo(qq, keyName);
            } else if (keyName.equals("market_mall_phone")) {
                String phone = mallInfoVO.getMarket_mall_phone();
                adminMapper.updateConfigInfo(phone, keyName);
            } else if (keyName.equals("market_mall_name")) {
                String name = mallInfoVO.getMarket_mall_name();
                adminMapper.updateConfigInfo(name, keyName);
            }
        }
        return 1;
    }

    @Override
    public ExpressInfoVO expressInfo() {
        ExpressInfoVO expressInfoVO = new ExpressInfoVO();
        List<MarketSystem> list = adminMapper.selectAllMallInfo();
        for (MarketSystem marketSystem : list) {
            if (marketSystem.getKeyName().equals("market_express_freight_min")) {
                expressInfoVO.setMarket_express_freight_min(marketSystem.getKeyValue());
            } else if (marketSystem.getKeyName().equals("market_express_freight_value")) {
                expressInfoVO.setMarket_express_freight_value(marketSystem.getKeyValue());
            }
        }
        return expressInfoVO;
    }

    @Override
    public int updateExpressConfig(ExpressInfoVO expressInfoVO) {
        List<MarketSystem> list = adminMapper.selectAllMallInfo();
        for (MarketSystem marketSystem : list) {
            String keyName = marketSystem.getKeyName();
            if (keyName.equals("market_express_freight_min")) {
                String freight_min = expressInfoVO.getMarket_express_freight_min();
                adminMapper.updateConfigInfo(freight_min, keyName);
            } else if (keyName.equals("market_express_freight_value")) {
                String freight_value = expressInfoVO.getMarket_express_freight_value();
                adminMapper.updateConfigInfo(freight_value, keyName);
            }
        }
        return 1;
    }

    @Override
    public OrderInfoVO orderInfo() {
        OrderInfoVO orderInfoVO = new OrderInfoVO();
        List<MarketSystem> list = adminMapper.selectAllMallInfo();
        for (MarketSystem marketSystem : list) {
            if (marketSystem.getKeyName().equals("market_order_unconfirm")) {
                orderInfoVO.setMarket_order_unconfirm(marketSystem.getKeyValue());
            } else if (marketSystem.getKeyName().equals("market_order_unpaid")) {
                orderInfoVO.setMarket_order_unpaid(marketSystem.getKeyValue());
            } else if (marketSystem.getKeyName().equals("market_order_comment")) {
                orderInfoVO.setMarket_order_comment(marketSystem.getKeyValue());
            }
        }
        return orderInfoVO;
    }

    @Override
    public int updateOrderConfig(OrderInfoVO orderInfoVO) {
        List<MarketSystem> list = adminMapper.selectAllMallInfo();
        for (MarketSystem marketSystem : list) {
            String keyName = marketSystem.getKeyName();
            if (keyName.equals("market_order_unconfirm")) {
                String unconfirm = orderInfoVO.getMarket_order_unconfirm();
                adminMapper.updateConfigInfo(unconfirm, keyName);
            } else if (keyName.equals("market_order_unpaid")) {
                String unpaid = orderInfoVO.getMarket_order_unpaid();
                adminMapper.updateConfigInfo(unpaid, keyName);
            } else if (keyName.equals("market_order_comment")) {
                String comment = orderInfoVO.getMarket_order_comment();
                adminMapper.updateConfigInfo(comment, keyName);
            }
        }
        return 1;
    }

    @Override
    public WxInfoVO wxInfo() {
        WxInfoVO wxInfoVO = new WxInfoVO();
        List<MarketSystem> list = adminMapper.selectAllMallInfo();
        for (MarketSystem marketSystem : list) {
            if (marketSystem.getKeyName().equals("market_wx_index_new")) {
                wxInfoVO.setMarket_wx_index_new(marketSystem.getKeyValue());
            } else if (marketSystem.getKeyName().equals("market_wx_index_topic")) {
                wxInfoVO.setMarket_wx_index_topic(marketSystem.getKeyValue());
            } else if (marketSystem.getKeyName().equals("market_wx_share")) {
                wxInfoVO.setMarket_wx_share(marketSystem.getKeyValue());
            } else if (marketSystem.getKeyName().equals("market_wx_index_brand")) {
                wxInfoVO.setMarket_wx_index_brand(marketSystem.getKeyValue());
            } else if (marketSystem.getKeyName().equals("market_wx_catlog_goods")) {
                wxInfoVO.setMarket_wx_catlog_goods(marketSystem.getKeyValue());
            } else if (marketSystem.getKeyName().equals("market_wx_catlog_list")) {
                wxInfoVO.setMarket_wx_catlog_list(marketSystem.getKeyValue());
            } else if (marketSystem.getKeyName().equals("market_wx_index_hot")) {
                wxInfoVO.setMarket_wx_index_hot(marketSystem.getKeyValue());
            }
        }
        return wxInfoVO;
    }

    @Override
    public int updateWxConfig(WxInfoVO wxInfoVO) {
        List<MarketSystem> list = adminMapper.selectAllMallInfo();
        for (MarketSystem marketSystem : list) {
            String keyName = marketSystem.getKeyName();
            if (keyName.equals("market_wx_index_new")) {
                String unconfirm = wxInfoVO.getMarket_wx_index_new();
                adminMapper.updateConfigInfo(unconfirm, keyName);
            } else if (keyName.equals("market_wx_index_topic")) {
                String unpaid = wxInfoVO.getMarket_wx_index_topic();
                adminMapper.updateConfigInfo(unpaid, keyName);
            } else if (keyName.equals("market_wx_share")) {
                String comment = wxInfoVO.getMarket_wx_share();
                adminMapper.updateConfigInfo(comment, keyName);
            } else if (keyName.equals("market_wx_index_brand")) {
                String comment = wxInfoVO.getMarket_wx_index_brand();
                adminMapper.updateConfigInfo(comment, keyName);
            } else if (keyName.equals("market_wx_catlog_goods")) {
                String comment = wxInfoVO.getMarket_wx_catlog_goods();
                adminMapper.updateConfigInfo(comment, keyName);
            } else if (keyName.equals("market_wx_catlog_list")) {
                String comment = wxInfoVO.getMarket_wx_catlog_list();
                adminMapper.updateConfigInfo(comment, keyName);
            } else if (keyName.equals("market_wx_index_hot")) {
                String comment = wxInfoVO.getMarket_wx_index_hot();
                adminMapper.updateConfigInfo(comment, keyName);
            }
        }
        return 1;
    }

    @Override
    public List<StatInnerUser> statUser() {
        List<StatInnerUser> list = adminMapper.statUser();
        return list;
    }

    @Override
    public List<StatInnerOrder> statOrder() {
        List<StatInnerOrder> list = adminMapper.statOrder();
        return list;
    }

    @Override
    public List<StatInnerGoods> statGoods() {
        List<StatInnerGoods> list = adminMapper.statGoods();
        return list;
    }

    @Override
    public PageInfo<MarketRole> listRole(BasePageInfo basePageInfo, String name) {
        //开启分页
        PageHelper.startPage(basePageInfo.getPage(), basePageInfo.getLimit());
        MarketRoleExample marketRoleExample = new MarketRoleExample();
        //排序
        marketRoleExample.setOrderByClause(basePageInfo.getSort() + " " + basePageInfo.getOrder());
        MarketRoleExample.Criteria criteria = marketRoleExample.createCriteria();
        //name是模糊查询
        if (!StringUtil.isEmpty(name)) {
            criteria.andNameLike("%" + name + "%");
        }
        criteria.andDeletedEqualTo(false);
        //执行查询过程中拼接分页信息
        List<MarketRole> list = adminMapper.selectByRoleExample(marketRoleExample);
        PageInfo<MarketRole> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public int createRole(RoleCreateBO createBO) {
        int affectedRows = adminMapper.createRole(createBO);
        return affectedRows;
    }

    /**
     * 后端-管理员-删除管理员账户信息
     * @param admin       是当前登录的用户信息
     * @param marketAdmin 是要删除的账户信息
     * @return code 状态码，根据状态码判断删除状态
     * @author zlh
     */
    @Override
    public int deleteAdmin(MarketAdmin admin, MarketAdmin marketAdmin) {
        Integer[] roleIds = admin.getRoleIds();
        for (Integer roleId : roleIds) {
            if (roleId == 1) {
                try {
                    if (1 == marketAdmin.getId()) {
                        return 300;
                    }
                    adminMapper.deleteAdminByMarketAdmin(marketAdmin.getId());
                    return 200;
                } catch (Exception e) {
                    e.printStackTrace();
                    return 404;
                }
            }
        }
        return 300;
    }

    /**
     * 后端-管理员-编辑管理员信息
     * @param adminCreateVo
     * @return
     */
    @Override
    public MarketAdminUpdateAdminVo updateAdmin(MarketAdminAdminCreateVo adminCreateVo) {

        try {
            int count = adminMapper.updateAdmin(adminCreateVo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        MarketAdminUpdateAdminVo marketAdminUpdateAdminVo = adminMapper.selectAdminByUpdateAdminId(adminCreateVo.getId());
        return marketAdminUpdateAdminVo;
    }

    @Override
    public CommonData<MarketIssue> selectAllIssue(BasePageInfo info) {
        PageHelper.startPage(info.getPage(), info.getLimit());
        MarketIssueExample example = new MarketIssueExample();
        List<MarketIssue> list = adminMapper.selectAllIssue(example);
        PageInfo<MarketIssue> pageInfo = new PageInfo<>(list);
        return CommonData.data(pageInfo);
    }

    @Override
    public MarketCreateIssueVo createIssue(MarketIssue marketIssue) {
        int count = adminMapper.insertNewIssue(marketIssue);
        MarketCreateIssueVo marketCreateIssueVo = adminMapper.selectIssueById(marketIssue.getId());
        return marketCreateIssueVo;
    }

    @Override
    public MarketCreateIssueVo updateIssue(MarketCreateIssueVo issuePo) {
        int count = adminMapper.updateIssueById(issuePo);
        MarketCreateIssueVo marketCreateIssueVo = adminMapper.selectIssueById(issuePo.getId());
        return marketCreateIssueVo;
    }

    @Override
    public int deleteIssueById(MarketCreateIssueVo issueBo) {
        int count = adminMapper.deleteIssueById(issueBo);
        if (count == 1) {
            return 200;
        }
        return 404;
    }

    public int updateRole(MarketRole marketRole) {
        int affectedRows = adminMapper.updateRole(marketRole);
        return affectedRows;
    }

    @Override
    public int deleteRole(MarketRole marketRole) {
        int affectedRows = adminMapper.deleteRole(marketRole);
        return affectedRows;
    }

    @Override
    public List<RoleOptionsVO> optionsRole() {
        MarketRoleExample marketRoleExample = new MarketRoleExample();
        List<RoleOptionsVO> list = adminMapper.selectOptionByRoleExample(marketRoleExample);
        return list;
    }

    @Override
    public RolePermissionVO queryPermission(String roleId) {
        RolePermissionVO rolePermissionVO = new RolePermissionVO();
        List<String> assignedPermissionList = adminMapper.queryPermissionByRoleId(roleId);
        rolePermissionVO.setAssignedPermissions(assignedPermissionList);
        List<GPermissionInfoVO> gPermissionVOList = new ArrayList<>();
        List<Integer> gPermissionTypeList = adminMapper.queryGPermissionsType();
        for (Integer gtype : gPermissionTypeList) {
            GPermissionInfoVO gPermissionInfoVO = adminMapper.queryGPermissionInfo(gtype);
            List<PPermissionVO> pPermissionVOList = adminMapper.queryPPermissionInfo(gtype);
            List<PPermissionInfoVO> pPermissionInfoVOList = new ArrayList<>();
            for (PPermissionVO pPermissionVO : pPermissionVOList) {
                int p_type = pPermissionVO.getP_type();

                PPermissionInfoVO pPermissionVOInfo = adminMapper.queryPPermissionFinalInfo(p_type, gtype);
                List<CPermissionInfoVO> cPermissionVOList = adminMapper.queryCPermissionInfo(gtype, p_type);

                pPermissionVOInfo.setChildren(cPermissionVOList);
                pPermissionInfoVOList.add(pPermissionVOInfo);

            }
            gPermissionInfoVO.setChildren(pPermissionInfoVOList);
            gPermissionVOList.add(gPermissionInfoVO);
        }
        rolePermissionVO.setSystemPermissions(gPermissionVOList);
        return rolePermissionVO;

    }

    @Override
    public ArrayList<String> selectNameByUsername(Integer[] roleIds) {
        ArrayList<String> list = new ArrayList<>();
        //Integer[] ids = adminMapper.selectRolesIdByUsername(username);
        for (Integer id : roleIds) {
            String name = adminMapper.selectNameById(id);
            list.add(name);
        }
        return list;
    }

    @Override
    public ArrayList<String> selecPermissionsByUsername(Integer[] roleIds) {
        ArrayList<String> list = new ArrayList<>();
        //Integer[] ids = adminMapper.selectRolesIdByUsername(username);
        for (Integer id : roleIds) {
            ArrayList<String> perms = adminMapper.selectPermsByRolesId(id);
            list.addAll(perms);
        }

        return list;
    }

    @Override
    public int deleteBatch(List<Integer> ids) {
        try {
            for (Integer id : ids) {
                adminMapper.deleteMarketTopicById(id);
            }
            return 200;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 404;
    }

    /**
     * 更新最后登录时间_日志的功能
     *
     * @param ip
     * @param date
     * @param id
     * @author zlh
     */
    @Override
    public void updateIpAndLastLoginTime(String ip, Date date, Integer id) {
        MarketAdmin marketAdmin = new MarketAdmin();
        marketAdmin.setLastLoginIp(ip);
        marketAdmin.setLastLoginTime(date);
        marketAdmin.setId(id);
        adminMapper.updateByPrimaryKeySelective(marketAdmin);
    }

    /**
     * admin_admin_list
     * 根据用户名搜寻管理员账户
     *
     * @param info
     * @return
     */
    @Override
    public CommonData<MarketAdminAdminListVo> selectAdminList1(BasePageInfo1 info) {
        PageHelper.startPage(info.getPage(), info.getLimit());
        MarketAdminExample example = new MarketAdminExample();
        List<MarketAdminAdminListVo> list = adminMapper.selectByAdminAdminUsername(info.getUsername());
        PageInfo<MarketAdminAdminListVo> pageInfo = new PageInfo<>(list);

        return CommonData.data(pageInfo);

    }

    @Override
    public ArrayList<String> selectPermissionByPermissions(ArrayList<String> list) {
        ArrayList<String> list1 = new ArrayList<>();
        for (String s : list) {
            ArrayList<String> list2 = adminMapper.selectByPermissions(s);
            list1.addAll(list2);
        }
        return list1;
    }
    public int insertPermissions(PermissionsBO permissionsBO) {
        List<String> permissions = permissionsBO.getPermissions();
        Integer roleId = permissionsBO.getRoleId();
        for (String permission : permissions) {
            marketPermissionMapper.insertPermisssion(roleId,permission);
        }
        return 1;

    }


    @Override
    public MarketRole queryMarketRole(Integer id) {
        MarketRole marketRole = adminMapper.queryMarketRoleById(id);
        return marketRole;
    }


}
